View Javadoc
1 /* 2 * (C) 2002 David Carr david@carr.name 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 19 package net.sourceforge.mflow; 20 21 import java.awt.BorderLayout; 22 import java.awt.event.ActionEvent; 23 import java.awt.event.ActionListener; 24 25 import javax.swing.JButton; 26 import javax.swing.JFrame; 27 import javax.swing.JTable; 28 import javax.swing.event.TableModelListener; 29 import javax.swing.table.TableModel; 30 31 import net.sourceforge.mflow.api.Plugin; 32 import net.sourceforge.mflow.api.PluginManager; 33 34 /*** 35 * @author carrd 36 */ 37 class PluginManagerFrame extends JFrame { 38 /*** 39 * The plugin manager to get data from 40 */ 41 private PluginManager pluginManager; 42 43 /*** 44 * @return the plugin manager to get data from 45 */ 46 protected final PluginManager getPluginManager() { 47 return this.pluginManager; 48 } 49 50 /*** 51 * Constructs a new instance of the frame 52 * 53 * @param aPluginManager the plugin manager to use 54 */ 55 public PluginManagerFrame(final PluginManager aPluginManager) { 56 super("MFlow Plugin Manager"); 57 this.pluginManager = aPluginManager; 58 PluginTableModel tm = new PluginTableModel(); 59 final JTable table = new JTable(tm); 60 getContentPane().setLayout(new BorderLayout()); 61 getContentPane().add(table, BorderLayout.CENTER); 62 JButton toggle = new JButton("Load/Unload"); 63 toggle.addActionListener(new ActionListener() { 64 public final void actionPerformed(final ActionEvent e) { 65 int row = table.getSelectedRow(); 66 if (row != -1) { 67 Plugin p = getPluginManager().getKnownPlugins()[row]; 68 getPluginManager().toggleLoading(p); 69 table.repaint(); 70 } 71 } 72 }); 73 getContentPane().add(toggle, BorderLayout.SOUTH); 74 } 75 76 /*** 77 * A table model for plugin listings 78 */ 79 private class PluginTableModel implements TableModel { 80 /*** 81 * @return the number of rows for the plugin table 82 */ 83 public final int getRowCount() { 84 return getPluginManager().getKnownPlugins().length; 85 } 86 87 /*** 88 * @return the number of columns for the plugin table 89 */ 90 public final int getColumnCount() { 91 return 2; 92 } 93 94 /*** 95 * @param columnIndex the column index to get the name of 96 * @return the name of the column 97 */ 98 public final String getColumnName(final int columnIndex) { 99 switch (columnIndex) { 100 case 0 : 101 return "Plugin Name"; 102 case 1 : 103 return "Loaded"; 104 default : 105 return ""; 106 } 107 } 108 109 /*** 110 * @param columnIndex the index of the column to get the class for 111 * @return the class of the column 112 */ 113 public final Class getColumnClass(final int columnIndex) { 114 switch (columnIndex) { 115 case 0 : 116 return String.class; 117 case 1 : 118 return Boolean.class; 119 default : 120 return String.class; 121 } 122 } 123 124 /*** 125 * @param rowIndex the index of the row 126 * @param columnIndex the index of the column 127 * @return the value at the specified indices 128 */ 129 public final Object getValueAt(final int rowIndex, final int columnIndex) { 130 switch (columnIndex) { 131 case 0 : 132 return getPluginManager().getKnownPlugins()[rowIndex].getName(); 133 case 1 : 134 return new Boolean( 135 getPluginManager().getKnownPlugins()[rowIndex].isLoaded()); 136 default : 137 return ""; 138 } 139 } 140 141 /*** 142 * @param rowIndex the row index 143 * @param columnIndex the column index 144 * @return false; non-editable table model 145 */ 146 public final boolean isCellEditable( 147 final int rowIndex, 148 final int columnIndex) { 149 return false; 150 } 151 152 /*** 153 * This model is read-only. All arguments are ignored and no action is 154 * performed. 155 * 156 * @param aValue ignored 157 * @param rowIndex ignored 158 * @param columnIndex ignored 159 */ 160 public final void setValueAt( 161 final Object aValue, 162 final int rowIndex, 163 final int columnIndex) { 164 //This model is read-only 165 } 166 167 /*** 168 * @param l the listener to add 169 */ 170 public final void addTableModelListener(final TableModelListener l) { 171 //todo: implement model listener support 172 } 173 174 /*** 175 * @param l the listener to remove 176 */ 177 public final void removeTableModelListener(final TableModelListener l) { 178 //todo: implement model listener support 179 } 180 } 181 }

This page was automatically generated by Maven